package com.hiwhitley.chapter02;

/**
 * Created by hiwhitley on 17-2-14.
 */
public class ReverseList {
    public class Node {
        public int value;
        public Node next;

        public Node(int data) {
            this.value = data;
        }
    }

    public Node reverseList(Node head) {
        Node pre = null;
        Node next = null;
        while (head != null) {
            next = head.next;
            head = pre;
            pre = head;
            head = next;

        }
        return pre;
    }

    public class DoubleNode {
        public int value;
        public DoubleNode last = null;
        public DoubleNode next = null;

        public DoubleNode(int data) {
            this.value = data;
        }
    }

    public DoubleNode reverseDoubleList(DoubleNode head) {
        DoubleNode pre = null;
        DoubleNode next = null;
        while (head != null) {
            next = head.next;
            head.next = pre;
            head.last = next;
            pre = head;
            head = next;
        }

        return pre;
    }

}
